package com.CMS.client.ui.view;

import com.CMS.client.AdministrationService;
import com.CMS.client.AdministrationServiceAsync;
import com.CMS.server.domain.Administration;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class AdministrationView extends VLayout{
  
	private static final String DESCRIPTION = "AdministrationView";
	private TextItem mail;
	private TextItem url;
	private TextItem telephone;
	private TextItem razon;
	private TextItem direccion;
 
	public AdministrationView(){
		super();	  
		
		mail = new TextItem();
		mail.setTitle("E-Mail");
		url = new TextItem();
		url.setTitle("Url");
		telephone = new TextItem();
		telephone.setTitle("Telephone");
		razon = new TextItem();
		razon.setTitle("Raz&oacute;n Social");
		direccion = new TextItem();
		direccion.setTitle("Direcci&oacute;n");
	  
		final DynamicForm form = new DynamicForm();
		form.setWidth(400);
		form.setGroupTitle("Administraci&oacute;n");
		form.setIsGroup(true);
		form.setTitleOrientation(TitleOrientation.LEFT);   
		form.setAlign(Alignment.CENTER);
		form.setPadding(20);
		form.setFields(razon,direccion,telephone, mail, url);		
		
		VLayout layout = new VLayout(10);
		layout.setWidth100();
		layout.setHeight100();
		layout.setLayoutMargin(10);     	
		layout.setDefaultLayoutAlign(Alignment.CENTER);	
	    layout.addMember(form);
	    
		HLayout h = new HLayout();
		h.setWidth(200);
		h.setMembersMargin(5);
	
		com.smartgwt.client.widgets.Button aceptar = new com.smartgwt.client.widgets.Button("Guardar");
		aceptar.setIcon("icons/16/buttonNew.png");		
	
		com.smartgwt.client.widgets.Button cancelar = new com.smartgwt.client.widgets.Button("Cancelar");
		cancelar.setIcon("icons/16/buttonCancel.png");
		h.addMember(aceptar);
		h.addMember(cancelar);
		layout.addMember(h);
		layout.setMargin(100);

		VLayout content = new VLayout();
		content.setWidth100();
		content.setHeight100();
		content.setLayoutMargin(10);  
		content.setMembersMargin(40); 
		content.addMember(layout);
		content.setAlign(Alignment.CENTER);			
		content.setBorder("2px solid #C0C3C7");
		
		AdministrationServiceAsync rpc = GWT.create(AdministrationService.class);
		rpc.get(new AsyncCallback<Administration>() {
			
			@Override
			public void onSuccess(Administration result) {
					mail.setValue(result.getMail());
					telephone.setValue(result.getTelephone());
			}
			
			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
			}
		});
		this.addMember(content);
		this.draw();
	}
 
	public static class Factory implements ContextAreaFactory
 {
	 private String id;
	 
	 public Canvas create()
	 {
      //hay que crear la vista que vamos a llamar
	  AdministrationView view = new AdministrationView();
	  id = view.getID();
      return view;
     }
	 
	 public String getID()
	 {
	   return id;
	 }

	 public String getDescription() 
	 {
	   return DESCRIPTION;
	 }
 }
 
}
